home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Interactive 7
/
PC World Interactive 7.iso
/
program
/
ctutord.EXE
/
81.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-09-17
|
937b
|
49 lines
/*
There may be additional include files required depending
upon the compile product you are using. Typical compilers
include Microsoft C by Microsoft or Turbo C by Boland Int'l.
*/
#include <stdio.h>
#define INT 1
#define CHAR 2
#define MAX 10
struct test{
int type;
union {
int ival;
int cval;
} val;
}table[MAX];
main()
{
int i,v;
/* collect values of int or char types */
for(i=0; i<MAX; i++){
v=getchar();
/* scoop carriage return */
while((getchar()) != '\n') ;
/* Is it a number ? */
if( v<= '9' && v >= '0'){
table[i].val.ival= v - '0';
table[i].type=INT;
}
/* NO, must be a character */
else{
table[i].val.cval= v ;
table[i].type=CHAR;
}
}
/* now print them out */
for(i=0; i<MAX; i++){
if( table[i].type == INT)
printf("%d\n",table[i].val.ival);
else if( table[i].type == CHAR)
printf("%c\n",table[i].val.cval);
}
}